package com.nowcoder.community.event;/**
 * 功能描述
 *
 * @author 21775
 * @date 2022/09/24  20:43
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nowcoder.community.entity.Event;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *@ClassName ProducerEvent
 *@Description TODO 生产者事件
 *@Author 21775
 *@Date 2022/9/24 20:43
 *@Version 1.0
 */
@Component
public class ProducerEvent {
    @Resource
    private KafkaTemplate<String,Object> kafkaTemplate;

    // 处理事件
    public void fireEvent(Event event){
        //将事件发布到指定主题
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
    }
}
